<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        window.onload=function()
        {
            const btn1=document.getElementById("btn1");
            btn1.onclick=function()
            {
                const x=new XMLHttpRequest();
                //因为是满足同源策略，所以url可以简写
                x.open("GET","/data");
                //发送
                x.send();
                //
                x.onreadystatechange=function()
                {
                    if(x.readyState===4)
                    {
                        if(x.status>=200&&x.status<300)
                        {
                            console.log(x.response);
                        }
                    }
                };
            };
        };
    </script>
</head>
<body>
    <h1>尚硅谷</h1>
    <button id="btn1">点击获取用户数据</button>
</body>
</html>